#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,p,n;
int dp[200005][451];
void solve(){
	cin>>n;
	ll ans=0;
	for(int i=1;i*i<=n;i++)if(!((n-i*i)&1))ans=(ans+dp[(n-i*i)>>1][i])%p;
	cout<<ans<<'\n';
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
  	freopen("moon.in","r",stdin);
  	freopen("moon.out","w",stdout);
	cin>>t>>p;
	for(int i=0;i<=450;i++)dp[0][i]=1;
  	for(int i=1;i<=200000;i++){
	  	for(int j=1;j<=min(450,i);j++)dp[i][j]=dp[i-j][j];
	  	for(int j=1;j<=450;j++)dp[i][j]=(dp[i][j]+dp[i][j-1])%p;
	}
	while(t--)solve();
}
